package com.tanhua.app.controller;

import com.tanhua.app.service.VideoService;
import com.tanhua.domain.vo.PageBeanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
public class VideoController {

    @Autowired
    private VideoService videoService;

    @GetMapping(value = "/smallVideos", name = "小视频列表")
    public ResponseEntity findByPage(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        // 前端app有一个bug提交第一页居然为0
        if (pageNum < 1) {
            pageNum = 1;
        }
        PageBeanVo pageBeanVo = videoService.findByPage(pageNum, pageSize);
        return ResponseEntity.ok(pageBeanVo);
    }

    @PostMapping(value = "/smallVideos", name = "发布小视频")
    public ResponseEntity saveVideo(MultipartFile videoThumbnail, MultipartFile videoFile) throws Exception {
        return videoService.saveVideo(videoThumbnail, videoFile);
    }

    @PostMapping(value = "/smallVideos/{followUserId}/userFocus", name = "关注用户")
    public ResponseEntity userFocus(@PathVariable Long followUserId) {
        return videoService.userFocus(followUserId);
    }

    @PostMapping(value = "/smallVideos/{followUserId}/userUnFocus", name = "取消关注")
    public ResponseEntity userUnFocus(@PathVariable Long followUserId) {
        return videoService.userUnFocus(followUserId);
    }
}
